/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package program.beans;

import java.io.File;
import java.math.BigDecimal;
import java.sql.Timestamp;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Objects;

/**
 * Beans class to represent a bill with id, date, comp, amounts, billCopy cat
 * and type as attributes
 *
 * Responsible: Patrick
 */
public class Bill {

    private Timestamp id;
    private Date date;
    private Company comp;
    private ArrayList<BillAmount> amounts;
    private File billCopy;
    private Category cat;
    private int type;

    public Bill(Date date, Company comp, ArrayList<BillAmount> amounts, File billCopy, Category cat, int type) {
        this.date = date;
        this.comp = comp;
        this.amounts = amounts;
        this.billCopy = billCopy;
        this.cat = cat;
        this.type = type;
    }

    public Bill(Timestamp id, Date date, Company comp, ArrayList<BillAmount> amounts, File billCopy, Category cat, int type) {
        this.id = id;
        this.date = date;
        this.comp = comp;
        this.amounts = amounts;
        this.billCopy = billCopy;
        this.cat = cat;
        this.type = type;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public Company getComp() {
        return comp;
    }

    public void setComp(Company comp) {
        this.comp = comp;
    }

    public Date getDate() {
        return date;
    }

    public void setDate(Date date) {
        this.date = date;
    }

    public Timestamp getId() {
        return id;
    }

    public void setId(Timestamp id) {
        this.id = id;
    }

    public ArrayList<BillAmount> getAmounts() {
        return amounts;
    }

    public void setAmounts(ArrayList<BillAmount> amounts) {
        this.amounts = amounts;
    }

    public File getBillCopy() {
        return billCopy;
    }

    public void setBillCopy(File billCopy) {
        this.billCopy = billCopy;
    }

    public Category getCat() {
        return cat;
    }

    public void setCat(Category cat) {
        this.cat = cat;
    }

    public BigDecimal getAllBruttoAmounts() {
        BigDecimal brutto = new BigDecimal(0);
        for (BillAmount ba : amounts) {
            brutto = brutto.add(ba.getBrutto());
        }
        return brutto;
    }

    public BigDecimal getAllNettoAmounts() {
        BigDecimal netto = new BigDecimal(0);
        for (BillAmount ba : amounts) {
            netto = netto.add(ba.getNetto());
        }
        return netto;
    }

    public String getAllBruttoAmountsFormated() {
        return NumberFormat.getCurrencyInstance().format(this.getAllBruttoAmounts().doubleValue());
    }

    public String getAllNettoAmountsFormated() {
        return NumberFormat.getCurrencyInstance().format(this.getAllNettoAmounts().doubleValue());
    }

    public String getBid() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
        return sdf.format(id);
    }

    public String getBillDate() {
        SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy");
        return sdf.format(date);
    }

    @Override
    public String toString() {
        return "Bill{" + "id=" + id + ", date=" + date + ", comp=" + comp + ", amounts=" + amounts + ", billCopy=" + billCopy + '}';
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final Bill other = (Bill) obj;
        if (!Objects.equals(this.id, other.id)) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 79 * hash + Objects.hashCode(this.id);
        return hash;
    }
}
